<?php
/* ========== ########## ========== ########## ========== ########## ========== */
/*                                                                              */
/*   WHMCS v4.1.2 NULLED R4 by FLIPMODE  [ BAD SYNTAX ]                         */
/*                                                                              */
/*                             INTERNAL BAD SYNTAX NULLED VERSION: 2.5.9.6 R4   */
/*                                                                              */
/*   ALL files have been analysed, cleaned and nulled of:                       */
/*     - Call Backs  (100%)                                                     */
/*     - Link Backs (95%)                                                       */
/*     - Licensing  (100%)                                                      */
/*     - Remote Links + URL's                                                   */
/*                                                                              */
/*   WHMCS v4.1.2 RELEASED: 4th November 2009                                   */
/*    -> FIRST v4.1.2 NULL R1: 19th November 2009                               */
/*    -> UPDATED v4.1.2 NULL R4: 27th November 2009                             */
/*                                                                              */
/*   TESTING + VERIFICATION::                                                   */
/*     Files Cleaned, Nulled, Checked, Verified By:                             */
/*      -> FLIPMODE!                                                            */
/*     Decoded By:                                                              */
/*      -> FLIPMODE! + Unknown Decoder                                          */
/*     Tested By:                                                               */
/*      -> FLIPMODE!, LeetWolf, and 12 Anonymous Users...                       */
/*     WHMCS 4.1.2 Supplied By:                                                 */
/*      -> WHM CompleteShit Coder @ WHMCS.com                                   */
/*                                                                              */
/*                                                                              */
/*   IMPORTANT NOTE::                                                           */
/*   PLEASE NOTE THIS IS FOR TRIAL PURPOSES ONLY!                               */
/*                          LIKE IT? THEN BUY IT!                               */
/*                                                                              */
/* ========== ########## ========== ########## ========== ########## ========== */


require '../dbconnect.php';
require '../includes/functions.php';
require '../includes/adminfunctions.php';
$aInt = new adminInterface ('System Cleanup Operations');
$aInt->title = 'Cleanup Operations';
$aInt->sidebar = 'utilities';
$aInt->icon = 'cleanup';
ob_start ();
if ($action == 'deletemessages')
{
	$sqldate = tomysqldate ($date);
	$query = 'DELETE FROM tblemails WHERE date<\'' . mysql_real_escape_string ($sqldate) . '\'';
	$result = full_query ($query);
	logactivity ('' . 'Cleanup Operation: Deleted Messages Sent before ' . $date);
	infobox ('Cleanup Command Successful!', '' . 'Deleted All Messages Sent before ' . $date . ' (' . mysql_affected_rows () . ')');
}

if ($action == 'cleargatewaylog')
{
	$query = 'TRUNCATE tblgatewaylog';
	$result = full_query ($query);
	infobox ('Cleanup Command Successful!', 'Emptied Gateway Log');
	logactivity ('Cleanup Operation: Gateway Log Emptied');
}

if ($action == 'clearmailimportlog')
{
	$query = 'TRUNCATE tblticketmaillog';
	$result = full_query ($query);
	infobox ('Cleanup Command Successful!', 'Emptied Ticket Mail Import Log');
	logactivity ('Cleanup Operation: Ticket Mail Import Log Emptied');
}

if ($action == 'clearwhoislog')
{
	$query = 'TRUNCATE tblwhoislog';
	$result = full_query ($query);
	infobox ('Cleanup Command Successful!', 'Emptied WHOIS Lookup Log');
	logactivity ('Cleanup Operation: WHOIS Lookup Log Emptied');
}

if ($action == 'emptytemplatecache')
{
	$dh = opendir ($templates_compiledir);
	while (false !== $file = readdir ($dh))
	{
		if (is_file ($templates_compiledir . $file))
		{
			@unlink ($templates_compiledir . $file);
			continue;
		}
	}

	closedir ($dh);
	infobox ('Cleanup Command Successful!', 'Emptied Template Cache');
	logactivity ('Cleanup Operation: Template Cache Emptied');
}

if ($action == 'deleteattachments')
{
	$sqldate = tomysqldate ($date);
	$result = select_query ('tbltickets', '', 'date<=\'' . mysql_real_escape_string ($sqldate) . '\' AND attachment!=\'\'');
	while ($data = mysql_fetch_array ($result))
	{
		$attachment = $data['attachment'];
		$attachment = explode ('|', $attachment);
		foreach ($attachment as $file)
		{
			@unlink ($attachments_dir . $file);
		}
	}

	$result = select_query ('tblticketreplies', '', 'date<=\'' . mysql_real_escape_string ($sqldate) . '\' AND attachment!=\'\'');
	while ($data = mysql_fetch_array ($result))
	{
		$attachment = $data['attachment'];
		$attachment = explode ('|', $attachment);
		foreach ($attachment as $file)
		{
			@unlink ($attachments_dir . $file);
		}
	}

	logactivity ('' . 'Cleanup Operation: Deleted Attachments Uploaded before ' . $date);
	infobox ('Cleanup Command Successful!', '' . 'Deleted All Attachments Uploaded before ' . $date);
}

$attachmentssize = $attachmentscount = 0;
$dh = opendir ($attachments_dir);
while (false !== $file = readdir ($dh))
{
	$fullpath = $attachments_dir . $file;
	if ((is_file ($fullpath) AND $file != 'index.php'))
	{
		$attachmentssize += filesize ($fullpath);
		++$attachmentscount;
		continue;
	}
}

closedir ($dh);
$attachmentssize /= 1024 * 1024;
$attachmentssize = round ($attachmentssize, 2);
echo $infobox;
echo '
<p>You can clear some of the log tables from here to reduce the size of the database & delete old attachments to reduce disk space usage.</p>

<table width="100%" cellspacing="0" cellpadding="0"><tr><td width="49%">

<div class="contentbox">
<b>Empty Gateway Log</b> <input type="button" value=" Go &raquo; " onClick="window.location=\'';
echo $PHP_SELF;
echo '?action=cleargatewaylog\'" class="button">
</div>

<br>

<div class="contentbox">
<b>Empty Ticket Mail Import Log</b> <input type="button" value=" Go &raquo; " onClick="window.location=\'';
echo $PHP_SELF;
echo '?action=clearmailimportlog\'" class="button">
</div>

</td><td width="2%"></td><td width="49%">

<div class="contentbox">
<b>Empty WHOIS Lookup Log</b> <input type="button" value=" Go &raquo; " onClick="window.location=\'';
echo $PHP_SELF;
echo '?action=clearwhoislog\'" class="button">
</div>

<br>

<div class="contentbox">
<b>Empty Template Cache</b> <input type="button" value=" Go &raquo; " onClick="window.location=\'';
echo $PHP_SELF;
echo '?action=emptytemplatecache\'" class="button">
</div>

</td></tr></table>

<br>

<div class="contentbox">
<form method="post" action="';
echo $PHP_SELF;
echo '?action=deletemessages">
<b>Delete Saved Emails</b><br>
';
$result = select_query ('tblemails', 'COUNT(*)', '');
$data = mysql_fetch_array ($result);
$num_rows = $data[0];
echo 'Number of Saved Email Messages: <b>' . $num_rows . '</b>';
echo '<br>
Delete Saved Emails Sent Before: <input type="text" name="date" class="datepick"> <input type="submit" value="Delete" class="button"></form>
</div>

<br>

<div class="contentbox">
<form method="post" action="';
echo $PHP_SELF;
echo '?action=deleteattachments">
<b>Delete Old Attachments</b><br>
';
echo 'Number of Saved Attachments: <b>' . $attachmentscount . '</b><br>Filesize of Saved Attachments: <b>' . $attachmentssize . ' MB</b>';
echo '<br>
Delete Attachments Uploaded Before: <input type="text" name="date" class="datepick"> <input type="submit" value="Delete" class="button"></form>
</div>

';
$content = ob_get_contents ();
ob_end_clean ();
$aInt->content = $content;
$aInt->display ();
?>